package com.jilefojing.beans.pojos.enhanced;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

import com.jilefojing.beans.enums.ItemTypeEnumForSource;
import com.jilefojing.beans.enums.forrsourceuser.RelationTypeEnumForRSourceUser;
import com.jilefojing.beans.pojos.RSourceUser;
import com.jilefojing.beans.pojos.enhanced.base.BaseEnhanced;

/**
 * 
 * @author 作者 jgshun
 * @date 创建时间 2016年07月21日 00时01分07秒
 */
public class EnhancedRSourceUser extends BaseEnhanced {
	public EnhancedRSourceUser(RSourceUser rSourceUser) {
		// TODO 自动生成 细微误差自己调整
		if (rSourceUser.getId() != null) {
			this.id = rSourceUser.getId();
		}
		if (rSourceUser.getUserId() != null) {
			EnhancedUser enhancedUser = new EnhancedUser();
			enhancedUser.setId(rSourceUser.getUserId());
			this.enhancedUser = enhancedUser;
		}
		if (rSourceUser.getItemType() != null) {
			this.itemType = ItemTypeEnumForSource.getItemTypeEnumByCode(rSourceUser.getItemType());
		}

		if (rSourceUser.getItemId() != null && this.itemType != null) {
			try {
				Class<? extends BaseEnhanced> _EnhancedClass = this.itemType.getEnhancedItemClass();
				BaseEnhanced _EnhancedItem = _EnhancedClass.newInstance();
				for (Method _Method : _EnhancedClass.getDeclaredMethods()) {
					if (_Method.getName().equals("setId")) {
						_Method.invoke(_EnhancedItem, rSourceUser.getItemId());
						break;
					}
				}
				this.enhancedItem = _EnhancedItem;
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}

		this.createTime = rSourceUser.getCreateTime();

		if (rSourceUser.getRelationType() != null) {
			this.relationType = RelationTypeEnumForRSourceUser.getRelationTypeByCode(rSourceUser.getRelationType());
		}
	}

	public EnhancedRSourceUser() {
	}

	private long id;
	private EnhancedUser enhancedUser;
	private ItemTypeEnumForSource itemType;
	private BaseEnhanced enhancedItem;
	private Date createTime;
	private RelationTypeEnumForRSourceUser relationType;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public EnhancedUser getEnhancedUser() {
		return enhancedUser;
	}

	public void setEnhancedUser(EnhancedUser enhancedUser) {
		this.enhancedUser = enhancedUser;
	}

	public ItemTypeEnumForSource getItemType() {
		return itemType;
	}

	public void setItemType(ItemTypeEnumForSource itemType) {
		this.itemType = itemType;
	}

	public BaseEnhanced getEnhancedItem() {
		return enhancedItem;
	}

	public void setEnhancedItem(BaseEnhanced enhancedItem) {
		this.enhancedItem = enhancedItem;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public RelationTypeEnumForRSourceUser getRelationType() {
		return relationType;
	}

	public void setRelationType(RelationTypeEnumForRSourceUser relationType) {
		this.relationType = relationType;
	}

}